package org.ciallo.easytokendemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.ciallo.easytokendemo.entity.User;
import org.ciallo.easytokendemo.persistence.UserMapper;
import org.ciallo.easytokendemo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @Description:
 * @Author: Jukomu
 * @Package: org.ciallo.easytokendemo.demo.service.impl
 * @Project: easy-token-demo
 * @name: UserServiceImpl
 * @Date: 2025-05-16
 * @Filename: UserServiceImpl
 */
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class UserServiceImpl implements IUserService {
    private final UserMapper userMapper;

    @Override
    public User queryUser(String uuid) {
        User user = userMapper.selectById(uuid);
        return user;
    }

    @Override
    public List<User> queryUserList(String name) {
        User user = new User();
        user.setName(name);
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.setEntity(user);
        List<User> users = userMapper.selectList(userQueryWrapper);
        return users;
    }

    @Override
    public boolean insertUser(String uuid, String name, String password) {
        User user = new User(uuid, name, password);
        return userMapper.insert(user) > 0;
    }

    @Override
    public boolean verifyUser(String uuid, String password) {
        User user = queryUser(uuid);
        if (user == null) {
            return false;
        }
        String password1 = user.getPassword();
        return password.equals(password1);
    }
}
